using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel._Admin.SysOrgVms
{
    public partial class SysOrgListVm : BasePagedListVM<SysOrgView, SysOrgSearcher>
    {

        protected override IEnumerable<IGridColumn<SysOrgView>> InitGridHeader()
        {
            return new List<GridColumn<SysOrgView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.IsHrOrg),
                this.MakeGridHeader(x => x.IsFinanceOrg),
                this.MakeGridHeader(x => x.IsSupplyChainOrg),
                this.MakeGridHeader(x => x.ParentName),
                this.MakeGridHeader(x => x.Order),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysOrgView> GetSearchQuery()
        {
            var query = DC.Set<SysOrg>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckEqual(Searcher.IsHrOrg, x=>x.IsHrOrg)
                .CheckEqual(Searcher.IsFinanceOrg, x=>x.IsFinanceOrg)
                .CheckEqual(Searcher.IsSupplyChainOrg, x=>x.IsSupplyChainOrg)
                .CheckEqual(Searcher.ParentId, x=>x.ParentId)
                .Select(x => new SysOrgView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    IsHrOrg = x.IsHrOrg,
                    IsFinanceOrg = x.IsFinanceOrg,
                    IsSupplyChainOrg = x.IsSupplyChainOrg,
                    ParentName = x.Parent.Name,
                    Order = x.Order,
                })
                .OrderBy(x => x.Order ?? 99.99m)
                .ThenBy(x => x.ID);
            return query;
        }

    }

    public class SysOrgView : SysOrg{
        [Display(Name = "组织名称")]
        public String ParentName { get; set; }
    
        [Display(Name = "排序")]
        public decimal? Order { get; set; }

    }
}
